const koaBody = require('koa-body')
const path = require('path')

let dirname = String(__dirname);
dirname = dirname.split(path.sep)
dirname.pop()
dirname = path.join(...dirname)

module.exports = koaBody({
  multipart: true,
  formidable: {
    uploadDir: path.resolve(dirname, 'public/avator'),
    keepExtensions: true,
    onFileBegin: function(name, file){
      console.log(name,file);
      let { path } = file;
      let dir = path.slice(0,path.lastIndexOf('\\')+1)
      let rename = file.name;
      file.path = dir+rename;
      console.log(file.path)
    }
  }
})
